package top.tungsword.webconsole.controller.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.tungsword.webconsole.biz.response.WebReturnInfo;
import top.tungsword.webconsole.biz.service.app.AppBiz;
import top.tungsword.webconsole.biz.param.AppParam;
import top.tungsword.webconsole.dal.entity.SsoApp;

import java.util.List;

@Controller
@RequestMapping("/app")
public class AppController {
    @Autowired
    private AppBiz appBiz;

    /**
     * 画面跳转
     * @return
     */
    @GetMapping("/appinfo")
    public String appinfo(ModelMap model, AppParam param){
        List<SsoApp> ssoAppList =appBiz.findAppList(param);
        model.addAttribute("ssoAppList", ssoAppList);
        model.addAttribute("appParam", param);
        return "app/appinfo";
    }

    @PostMapping("/addApp")
    @ResponseBody
    public WebReturnInfo<String> addApp(SsoApp param){
        return appBiz.addApp(param);
    }

    @PostMapping("/deleteApp")
    @ResponseBody
    public WebReturnInfo<String> deleteApp(SsoApp param){
        return appBiz.deleteApp(param);
    }

    @PostMapping("/updateApp")
    @ResponseBody
    public WebReturnInfo<String> updateApp(SsoApp param){
        return appBiz.updateApp(param);
    }
}
